<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input type="text">
<input type="button" value="平方" onclick="res()">
<h3>
  结果：<span></span>
</h3>
</body>
<script>
  let t = document.querySelector("input")
  let s = document.querySelector("span")
  function res() {
    if (isNaN(t.value)) {
      s.innerText = "输入错误！！！笨蛋"
      return;
    }
    s.innerText = f(t.value);
  }
  function f(num) {
    return num * 1 + num*1
  }
</script>
</html>